package br.com.gp.fabrica;

import java.util.ArrayList;
import java.util.List;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import br.com.gp.gerentes.GerenteCadastro;
import br.com.gp.gerentes.GerenteCadastroImpl;
import br.com.gp.hibernate.HibernateUtilitario;

@Configuration
public class FabricaGerentes {
	
	private List<Advisor> lista;
	public @Bean GerenteCadastro gerenteCadastro(){
		GerenteCadastroImpl gc= new GerenteCadastroImpl();
		gc.setHib(new HibernateUtilitario());
		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.setTarget(gc);
		proxyFactory.addAdvisors(getLista());
		return (GerenteCadastro) proxyFactory.getProxy();
	}
	public List<Advisor> getLista() {
		if(lista==null){
			FabricaInterceptPoint fabrica = new FabricaInterceptPoint();
			lista = new ArrayList<Advisor>();
			lista.addAll(fabrica.getInterceptPointConsulta());
			lista.addAll(fabrica.getInterceptPointSaveOrUpdate());
		}
		return lista;
	}
	public void setLista(List<Advisor> lista) {
		this.lista = lista;
	}
	
}